import vim
from functools import wraps
command = vim.command


def errorWrap(func):
    @wraps(func)
    def deco(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except Exception as e:
            error_info = repr(e)
            command(f'let g:mapping_failure={repr(error_info)}')
            command(f"echo 'mapping failure' g:mapping_failure")

    return deco
